package com.ws.eduservice.controller;


import com.ws.commonutils.R;
import com.ws.eduservice.entity.subject.OneSubject;
import com.ws.eduservice.entity.subject.TwoSubject;
import com.ws.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author ws
 * @since 2024-12-04
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    @PostMapping("addSubject")
    public R readFile(MultipartFile file) {
        subjectService.readFileSave(subjectService,file);
        return R.ok();
    }

    @GetMapping("getAllSubject")
    public R selectAll() {
        List<OneSubject> oneSubjects=subjectService.getOneTwoSubject();
        List<TwoSubject> twoSubjectList=new ArrayList<>();
        for (OneSubject oneSubject : oneSubjects) {
            twoSubjectList.addAll(oneSubject.getChildren());
        }
        return R.ok().data("list",oneSubjects).data("twoSubjectList",twoSubjectList);
    }
}

